import { getAreaObj, uploadType, regularRule } from '@/utils/util'

export const formConfig = {
	inline: false,
	showBtn: true,
	labelPosition: 'left',
	labelWidth: '120px',
	column: [
		{
			label: '类型',
			prop: 'category',
			type: 'radio',
			span: 24,
			disabled: true,
			dicData: [
				{
					label: '老人',
					value: 0,
				},
				{
					label: '员工',
					value: 1,
				},
			],
			rules: [{ required: true, message: '请选择类型' }],
		},
		{
			label: '证件号码',
			prop: 'idCard',
			disabled: true,
			rules: [{ required: true, pattern: regularRule.idCard, message: '请输入正确的证件号码' }],
			span: 24,
		},
		{
			label: '姓名',
			prop: 'whiteName',
			disabled: true,
			rules: [{ required: true, message: '请输入姓名' }],
			span: 24,
		},
		{
			label: '联系方式',
			prop: 'whitePhone',
			disabled: true,
			rules: [{ required: true, pattern: regularRule.phone, message: '请输入正确的联系方式' }],
			span: 24,
		},
		{
			label: '提交申请原因情况说明',
			prop: 'representation',
			type: 'textarea',
			maxlength: '140',
			rows: 3,
			showWordLimit: true,
			disabled: true,
			rules: [{ required: true, message: '请输入提交申请原因情况说明' }],
			span: 24,
		},
		{
			label: '证明材料',
			prop: 'material',
			type: 'upload',
			fileType: uploadType.fileMetaType,
			listType: 'text',
			labelPosition: 'top',
			uploadTip: '支持文件格式：pdf、图片。',
			rules: [{ required: true, message: '请上传证明材料' }],
			showFileList: true,
			limit: 4,
			multiple: true,
			span: 24,
		},
		{
			label: '审核结果',
			prop: 'approvalStatus',
			propName: 'approvalStatusLabel',
			type: 'radio',
			span: 24,
			dicData: [
				{
					label: '通过',
					value: 0,
				},
				{
					label: '驳回',
					value: 1,
				},
			],
			control: (e, model) => {
				return {
					approvalInfo: {
						display: e == 1,
					},
				}
			},
		},
		{
			label: '驳回原因',
			prop: 'approvalInfo',
			type: 'textarea',
			maxlength: '140',
			rows: 3,
			showWordLimit: true,
			rules: [{ required: true, message: '请输入驳回原因' }],
			span: 24,
		},
	],
}

export const searchConfig = {
	inline: true,
	showBtn: true,
	labelPosition: 'left',
	column: [
		{
			label: '所属区',
			prop: 'areas',
			type: 'AplidAreaSelect',
			regionGrade: 3,
			span: 8,
		},
		{
			label: '养老机构名称',
			prop: 'organizationName',
			type: 'input',
			span: 8,
		},
		{
			label: '姓名',
			prop: 'whiteName',
			type: 'input',
			span: 8,
		},
		{
			label: '身份证号',
			prop: 'idCard',
			type: 'input',
			span: 8,
		},
		{
			label: '审批结果',
			prop: 'approvalStatus',
			type: 'select',
			dicData: [
				{ label: '通过', value: 0 },
				{ label: '不通过', value: 1 },
				{ label: '待审核', value: 2 },
			],
			span: 8,
		},
		{
			label: '申请人',
			prop: 'createUserName',
			type: 'input',
			span: 8,
		},
		{
			label: '提交申请时间',
			prop: 'createTimeBetween',
			type: 'dateBetween',
			format:'YYYY年MM月DD HH:mm:ss',
			valueFormat:"YYYY-MM-DD HH:mm:ss",
			span: 8,
		},
		{
			label: '类型',
			prop: 'category',
			type: 'select',
			span: 8,
			dicData: [
				{
					label: '老人',
					value: 0,
				},
				{
					label: '员工',
					value: 1,
				},
			],
		},
	],
}

export const tableConfig = {
	stripe: true,
	border: true,
	columns: [
		{ label: '所属区', prop: 'areaName' },
		{ label: '养老机构名称', prop: 'organizationName' },
		{ label: '姓名', prop: 'whiteName' },
		{ label: '身份证号', prop: 'idCard', plusXing: '2,2' },
		{ 
			label: '类型',
			prop: 'category',
			custome: 'tag',
			dicData: [
				{
					label: '老人',
					value: 0,
				},
				{
					label: '员工',
					value: 1,
				},
			],
		},
		{ label: '申请原因', prop: 'representation' },
		{ 
			label: '审批结果',
			prop: 'approvalStatus',
			custome: 'tag',
			dicData: [
				{
					label: '通过',
					value: 0,
					type: 'success'
				},
				{
					label: '驳回',
					value: 1,
					type: 'danger'
				},
				{
					label: '待审核',
					value: 2,
					type: 'primary'
				},
			],
		},
		{ label: '驳回原因', prop: 'approvalInfo' },
		{ label: '申请人', prop: 'createUserName' },
		{ label: '提交申请日期', prop: 'createTime' },	
		{
			label: '操作',
			prop: 'menu',
			width: 100,
			fixed: 'right',
		},
	],
}

export const api = {
	index: 'view_serviceObjectWhitelist_page',
	edit: 'view_serviceObjectWhitelist_approval',
}
export const baseConfig = {
	pageName: '拍照巡查白名单审核',
	dictcodes: ['INSPECTION_CONTENT'],
	rowKey: 'id',
	addLabel: '新增',
	tipLabel: 'organizationName',
	exportMqTopic: '/ning/export/',
	api,
	auth: {
		...api,
	},
	paramsObj: {
		organizationTypeList: [3],
	},
	menuBtn: [
		{
			icon: 'editor',
			label: '审核',
			type: 'primary',
			operate: 'edit',
			auth: api.edit,
			condition:"(row)=>row.approvalStatus == 2",
			text: true,
			show: true,
		},
	],
	dialogConfig: {
		width: '55%',
	},
	searchConfig,
	formConfig,
	tableConfig,
	detailConfig: formConfig,
	beforeOnLoadFormate: async (params) => {
		return new Promise((resolve, reject) => {
			const areaObj: any = getAreaObj(params.areas)
			resolve({
				...params,
				authProvince: areaObj.provinceId,
				authCity: areaObj.cityId,
				authArea: areaObj.areaId,
				areas: undefined,
			})
		})
	},
}
